<?php

namespace app\admin\service;

class Encrypt
{

    public static function randomPassword()
    {
        return getRandomStr(8);
    }

    public static function makeSalt()
    {
        return mt_rand(100000, 999999);
    }


    /**
     * 加密方式
     * @param $password
     * @param $salt
     * @return string
     */
    public static function encrypt($password, $salt)
    {
        return md5(md5($password) . $salt);
    }

    public static function checkPassword($password)
    {
        $password = trim($password);
        if (!strlen($password) >= 6) {
            return ['code' => 0, 'msg' => '密码必须大于6字符！'];
        }
        if (!preg_match("/^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,32}$/", $password)) {
            return ['code' => 0, 'msg' => '密码必需包含大小写字母、数字、符号任意两者组合！'];
        }
        return ['code' => 1, 'msg' => '密码复杂度通过验证！'];
    }
}